<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>AGV 任务添加</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/oksub.css">
</head>
<body>
<div class="ok-body layui-container ">
    <form class="layui-form layui-form-pane ok-form">

        <div class="layui-row layui-col-space10">
            <div class="layui-col-md8 ">
                <div class="layui-form-item">
                    <blockquote class="layui-elem-quote" id="nameMsg">
                        没有信息请重新打开
                    </blockquote>
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md8 ">
                <div class="layui-form-item">
                    <label class="layui-form-label">结束位置</label>
                    <div class="layui-input-block">
                        <select id="typeSelect" name="type" lay-filter="aihao"  lay-verify="required">
                            <option value="" selected>请选择需要修改的类型</option>
                            <option value="1">监控偏移地址</option>
                            <option value="2">完成偏移地址</option>
                            <option value="3">开始位置</option>
                            <option value="4">结束位置</option>
                            <option value="5">运行模板</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md8 ">
                <div class="layui-form-item">
                    <label class="layui-form-label">参数</label>
                    <div class="layui-input-block">
                        <input type="text" name="pram" placeholder="参数" autocomplete="off" class="layui-input"
                               lay-verify="required">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space15">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="add">确定修改</button>
                </div>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="/layui/layui.js"></script>
<script>
    let initData;


    function initForm(data) {
        let jsonString = JSON.stringify(data);
        initData = data;
        layui.use(["element", "jquery", "form", "layer"], function() {
            let form = layui.form;
            let $ = layui.jquery;
            var layer = layui.layer;
            var nameMag = '';
            var ids = [];
            if (initData.length <= 0){
                $("#nameMsg").html("未成功读取请重新打开")
            }else{
                for (const entity of initData) {
                    ids.push(entity.id);
                    nameMag += "["+entity.taskName+"]"+" "
                }
                $("#nameMsg").html("即将修改名称为 "+nameMag+ "数据，共计"+initData.length+"条" )
            }
            form.on('select(aihao)', function(data) {
                // data.elem 是触发事件的 select 元素
                // 使用 jQuery 获取选中的选项的文本内容
                var selectedText = $(data.elem).find('option:selected').text();
            });

            form.on("submit(add)", function (data) {
                data.field.ids = ids;

               /* layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                });*/

                var selectedText = $('#typeSelect').find('option:selected').text();

                layer.confirm('即将名称为 '+nameMag+" 数据共计 【"+initData.length+"】 条的 【"+selectedText+"】 参数全部修改成 【"+data.field.pram+"】 确认后无法撤销请谨慎操作！", {
                    btn: ['确认', '关闭'], //按钮
                    title: '高危操作', // 设置标题
                }, function(){
                    $.ajax({
                        url:'/data/batchReplace',
                        type:'POST',
                        data: JSON.stringify(data.field),
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (response) {
                            if (response.code===200){
                                layer.msg(response.msg, {
                                    time: 1800 // 2秒关闭（如果不配置，默认是3秒）
                                }, function() {
                                    //刷新页面
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                                });

                            }else{
                                layer.msg(response.msg);
                            }
                        }
                    });
                }, function(){

                });



                return false;
            });
            // 其他相关操作
        });
    }

</script>
</body>
</html>
